package com.zhb.controller;


import com.zhb.entity.Account;
import com.zhb.entity.Order;
import com.zhb.entity.OrderDto;
import com.zhb.feign.AccountFeign;
import com.zhb.service.IOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.zhb.responvo.ResponseInfo;

import java.math.BigDecimal;
import java.util.UUID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhb
 * @since 2021-09-09
 */
@RestController
@AllArgsConstructor
@RequestMapping("order")
@Slf4j
public class OrderController {

    private final IOrderService orderService;

    @RequestMapping("getOrderById")
    public ResponseInfo<Order> getOrderById(Integer orderId) {
        ResponseInfo<Order> responseInfo = new ResponseInfo<>();
        Order byId = orderService.getById(orderId);
        responseInfo.setData(byId);
        return responseInfo;
    }


    @RequestMapping("createOrder")
    public ResponseInfo<Order> createOrder(@RequestBody OrderDto orderDto) {
        log.info("create order:{}", orderDto);
        ResponseInfo<Order> responseInfo = new ResponseInfo<>();
        orderDto.setOrderNo(UUID.randomUUID().toString());
        orderDto.setAmount(orderDto.getPrice().multiply(new BigDecimal(orderDto.getCount())));
        orderService.createOrder(orderDto);
        return responseInfo;
    }
}
